package com.ticket.sass.admin.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ticket.sass.admin.dto.input.role.RoleListInput;
import com.ticket.sass.admin.mapper.RoleMapper;
import com.ticket.sass.admin.service.BaseService;
import com.ticket.sass.common.entity.tenant.RoleEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author ywb
 * @date 2022-3-22 17:46
 */
@Repository
public class RoleServiceImpl extends ServiceImpl<RoleMapper, RoleEntity> implements BaseService<RoleEntity> {

    public IPage<RoleEntity> getRoles(RoleListInput input) {
        Page<RoleEntity> page = new Page<>(input.getPageNum(), input.getPageSize());
        QueryWrapper<RoleEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return this.page(page, queryWrapper);
    }

    public List<RoleEntity> listByAdminId(Integer adminId) {
        QueryWrapper<RoleEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("map.admin_id", adminId);
        queryWrapper.isNull("role.deleted_at");
        queryWrapper.isNull("map.deleted_at");
        return this.baseMapper.listByAdminId(queryWrapper);
    }
}
